var imgUrl = new Array();
var ranNum = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20];
var check = false;

for(var i=1; i<21; i++){
	imgUrl[i] = '/image/testImg/image1 ('+i+').jpg';
}


$(document).ready(function() {
	setInterval(shuffleImg, 3*1000);
});


function shuffleImg(){
	ranNum = shuffle(ranNum);
	
	if(!check){
		check=true;
		for(var i=1; i<9; i++){
			$("#image"+i).attr("src",imgUrl[ranNum[i]]);
		}
	}else{
		var changeImgNum = Math.floor(Math.random() * 8)+1;
		for(var i=1; i<9; i++){
			if($("#image"+i).attr("src")===$("#image"+changeImgNum).attr("src")){
				changeImgNum = Math.floor(Math.random() * 8)+1;
				
			}
		}
		$("#image"+changeImgNum).attr("src",imgUrl[ranNum[changeImgNum]]);
		//$("#image"+changeImgNum).attr("src",imgUrl[ranNum[changeImgNum]]);
		
	}
	
	
		
	/*$("#images"+i).attr("src",imgUrl[i]);*/
	
}

function shuffle(arr){
	 if(arr instanceof Array)
	 {
	  var len = arr.length;
	  if(len == 1) return arr;
	  var i = len * 2;
	  while(i > 0)
	  {
	   var idx1 = Math.floor(Math.random()* len);
	   var idx2 = Math.floor(Math.random()* len);
	   if(idx1 == idx2) continue;
	   var temp = arr[idx1];
	   arr[idx1] = arr[idx2];
	   arr[idx2] = temp;
	   i--;
	  }
	 }
	 else
	 {
	  alert("No Array Object");
	 }
	 return arr;
	}
	